package com.kkb.retailer.center.filter;


import com.kkb.retailer.center.api.UserInfoService;
import com.kkb.retailer.center.common.pojo.UserDetailsImpl;
import com.kkb.retailer.center.common.pojo.UserInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Reference
    private UserInfoService userInfoService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserDetailsImpl userDetailsImpl = new UserDetailsImpl();
        UserInfo userInfo = userInfoService.findByUserName(username);

        if(userInfo==null){
            throw  new UsernameNotFoundException(username+"用户不存在");

        }

        userDetailsImpl.setUserName(username);
        userDetailsImpl.setUserPassword(userInfo.getUserPassword());

        return userDetailsImpl;
    }
}
